package org.moda.facade;

import org.moda.dsl.TableDSL;

import java.io.IOException;
import java.util.Map;

public class ExcelDSLExample {
    public static void main(String[] args) throws IOException {
        TableDSL excel = TableDSL.fromExcel("input.xlsx");

        // 过滤
        excel.filter(row -> (Double) row.get("Age") > 30)
             .print();

        // 投影
        excel.project("Name", "Age")
             .print();

        // 排序
        excel.sort("Age", true)
             .print();

        // 分组
        Map<Object, TableDSL> grouped = excel.groupBy("Department");
        for (Map.Entry<Object, TableDSL> entry : grouped.entrySet()) {
            System.out.println("Department: " + entry.getKey());
            entry.getValue().print();
            System.out.println();
        }

        // 链式操作
        excel.filter(row -> (Double) row.get("Age") > 30)
             .project("Name", "Age", "Department")
             .sort("Age", false)
             .saveToExcel("output.xlsx");
    }
}
